﻿using System;
using T.FAS.Runtime.Metadata.Entity;
using T.FAS.Runtime.Action.SPI;
using T.FAS.Runtime.Base.Entity;
using T.FAS.Runtime.DataAccess.Service;
using T.FAS.Runtime.Metadata.Entity.DataModel;

namespace T.FAS.Runtime.Action.Engine
{
    public class DQActionEngine : IActionExecuteProxy, IActionDataResultBuilder, IActionExecuteHandler
    {
        public void AfterExecute(SPI.ActionExecContext execContext)
        {

        }

        public void BeforeExecute(SPI.ActionExecContext execContext)
        {
            
        }

        public TResult BuildActionDataResult(SPI.ActionExecContext context, object dataResult)
        {
            return dataResult as TResult;
        }

        public object Execute(SPI.ActionExecContext context)
        {
            var action = context.MetaData as DataQuery;

            return UnifiedDataAccessServiceFactory.GetInstance().QueryDataForDataQuery(action, context.DataContent);
        }

        public void ExecuteError(SPI.ActionExecContext execContext, Exception exception)
        {
            
        }

        public object ExecuteWithSubEngine(IActionExecuteEngine subEngine, ActionExecContext context)
        {
            throw new NotImplementedException();
        }
    }
}
